/**
	Pulsar engine. Core.
	Debug dialog boxes (assertion failed, memory error)

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

namespace pl
{

const int _N_MAX_ASSERTS = 100;

// Information about PL_ASSERTW()/PL_ASSERTE()
struct AssertInfo
{
	const pl_char* file;     // source file name where assert is occured
	pl_uint32 line;          // source line number
	const pl_char* func;     // source function
	const pl_char* cond;     // failed condition
	const pl_char* msg;      // additional text message
	pl::AssertType type;	 // Assertion type
	pl_int32 passCount;      // number of passes
	pl_int32 totalCount;     // total number of assertion
};

class AppDebugWin
{
public:
	static bool init();
	static void term();

	static HandleResult onAssert(const pl_char* file, pl_uint32 line, const pl_char* func, const pl_char* cond, const pl_char* msg, pl::AssertType type);
	static HandleResult onMemErr(const pl_char* file, pl_uint32 line, const pl_char* func, void* p, pl_int64 size, pl::MemoryError idEvent);

private:
	AppDebugWin();
	~AppDebugWin();

	static INT_PTR CALLBACK _assertWndFunc(HWND dlgHandle, UINT msg, WPARAM wParam, LPARAM lParam);

	HandleResult _doHandleAssert(const pl_char* file, pl_uint32 line, const pl_char* func, const pl_char* cond, const pl_char* msg, pl::AssertType type);
	AssertInfo* _findAssertEvent(const pl_char* file, pl_uint32 line, const pl_char* func, const pl_char* cond, const pl_char* msg, pl::AssertType type);

	static AppDebugWin* _pClass;

	pl::Vector<AssertInfo, _N_MAX_ASSERTS> _assertList;
	bool _bIgnoreAllAsserts;

	DlgTemplate* _pDlgAssert;
	DlgTemplate* _pDlgMemError;
	DlgTemplate* _pDlgOutMem;
	DlgTemplate* _pDlgFatalError;
};



} // namespace pl

//
// End of file 'pulsar_app_win_debug.h'
//
